package com.jiezhuo.service.impl;

import com.jiezhuo.entity.cmeduSchool.JzgNewMenu;
import com.jiezhuo.mapper.center.JzgNewMenuMapper;
import com.jiezhuo.service.jzg.JzgNewMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiezhuo.utils.MeunUtils;
import com.jiezhuo.utils.R;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author com.jiezhuo
 * @since 2024-06-05
 */
@Service
public class JzgNewMenuServiceImpl extends ServiceImpl<JzgNewMenuMapper, JzgNewMenu> implements JzgNewMenuService {


    @Override
    public ArrayList<JzgNewMenu> getMenuTree(String userId) {
        ArrayList<JzgNewMenu> menuTree = this.getBaseMapper().getMenuTree(userId);

        ArrayList<JzgNewMenu> objects = MeunUtils.getJzgNewMenus(menuTree);

        return objects;
    }
    @Override
    public R getUserPermissionInfo(String userId) {
        HashMap<String, Object> stringObjectHashMap = this.getBaseMapper().getuserInfo(userId);
        ArrayList<HashMap<String ,Object>> userPermissionInfo = new ArrayList<>();
        if(stringObjectHashMap.get("JB").equals("区级")){
            userPermissionInfo=  this.getBaseMapper().getUserPermissionAll();
        }else {
            boolean pd=stringObjectHashMap.get("GL_XQDM").equals(stringObjectHashMap.get("GZ_XQDM"));
            if (!ObjectUtils.isEmpty(stringObjectHashMap) &&pd){
                userPermissionInfo = this.getBaseMapper().getUserPermissionInfo(stringObjectHashMap.get("GL_XQDM").toString());
            }
        }
        StringBuffer stringBuffer = new StringBuffer();

        userPermissionInfo.forEach(e->{
            stringBuffer.append(",'"+ e.get("NEW_XQDM")+"'");
        });
        String substring = stringBuffer.substring(1);

        return  R.ok().data("UserPermission",userPermissionInfo).data("estate",stringObjectHashMap.get("JB")).data("schools",substring) ;
    }


}
